//
//  AppDelegate.m
//  makepack_tools
//
//  Created by tangs on 2017/7/15.
//  Copyright © 2017年 tangs. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(open:)
                                                 name:@"open"
                                               object:nil];
}


- (void)applicationWillTerminate:(NSNotification *)aNotification {
    // Insert code here to tear down your application
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *) sender{
    return YES;
}

- (IBAction)open:(NSMenuItem *)sender {
    NSOpenPanel* openPanel = [NSOpenPanel openPanel];
    openPanel.canChooseFiles = true;
    openPanel.canChooseDirectories = false;
    openPanel.allowsMultipleSelection = false;
    openPanel.allowedFileTypes = @[@"csv"];
    [openPanel beginWithCompletionHandler:^(NSInteger result) {
        if (result == NSModalResponseOK) {
            NSMutableArray* filePaths = [[NSMutableArray alloc] init];
            for (NSURL* elemnet in [openPanel URLs]) {
                [filePaths addObject:[elemnet path]];
                NSDictionary* dic = @ {
                    @"path" : [elemnet path]
                };
                [[NSNotificationCenter defaultCenter] postNotificationName:@"selectedConfigFile"
                                                                    object:self
                                                                  userInfo:dic];
            }
        }
    }];
}

-(IBAction)selectAll:(id)sender {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"selectAll"
                                                        object:self
                                                      userInfo:nil];
}

-(IBAction)unselectAll:(id)sender {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"unselectAll"
                                                        object:self
                                                      userInfo:nil];
}

- (IBAction)exit:(id)sender {
    exit(0);
}

- (IBAction)startMakeApks:(id)sender {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"startMakeApks"
                                                        object:self
                                                      userInfo:nil];
}

@end
